package com.mybills.proj;

import com.google.gdata.data.calendar.CalendarEventFeed;
import com.google.gdata.util.AuthenticationException;
import com.mybills.proj.pf.googlecal;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Fetch extends ListActivity{
    
	//String[] events = null;
	//String email = "";
	//String pwd = "";
   
    @Override
	public void onCreate(Bundle savedInstanceState) {
		  super.onCreate(savedInstanceState);
		  String[] events = null;
		  
		  Bundle bundle=getIntent().getExtras();
		  StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
	        StrictMode.setThreadPolicy(policy);
       // email = bundle.getString("Email").toString();
        //pwd = bundle.getString("pwd").toString();
        MyBllsActivity mba = new MyBllsActivity();
        mba.setEmail(bundle.getString("Email").toString());
        mba.setPwd(bundle.getString("pwd").toString());
        pf p = new pf();
        pf.googlecal add = p.new googlecal();
        System.out.println("----------------try it-----------------");
        try {
			events = add.fetchEvents(mba);
		}
        catch (AuthenticationException e) {
			// TODO Auto-generated catch block
			System.out.print(e+"not added");
			super.onCreate(savedInstanceState);
	        setContentView(R.layout.notvalid);
			
		}  catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e+"not fetched");
		}
         setListAdapter(new ArrayAdapter<String>(this, R.layout.category_row, events));
		  
		  ListView lv = getListView();
		  lv.setTextFilterEnabled(true);
		lv.setOnItemClickListener(new OnItemClickListener() {
		    public void onItemClick(AdapterView<?> parent, View view,
		        int position, long id) {
		      // When clicked, show a toast with the TextView text
		      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
		          Toast.LENGTH_SHORT).show();
		    }
		  });
		}
    public void to_categories(View v){
    	Intent it = new Intent();
    	Bundle bundle=getIntent().getExtras();
    	//EditText et1 = (EditText)findViewById(R.id.email1);
       // EditText et2 = (EditText)findViewById(R.id.password1);
        it.putExtra("EMAIL",bundle.getString("Email").toString() );
    	it.putExtra("PWD",bundle.getString("pwd").toString());
    	it.setClass(this, Login.class);
    	startActivity(it);
    }
	}
	